home *** CD-ROM | disk | FTP | other *** search
/ The Sunday Times: The Month 2003 December / The Sunday Times - The Month 2003-12.iso / pc / engine / shell / shell.swf / scripts / frame_2 / DoAction_2.as next >
Encoding:
Text File  |  2003-11-10  |  9.0 KB  |  334 lines

  1. if(PLAY_MODE == "director")
  2. {
  3.    _global.lingo = function(str)
  4.    {
  5.       getURL("lingo:" + str,"");
  6.    };
  7. }
  8. else if(PLAY_MODE == "browser")
  9. {
  10.    _global.lingo = function(str)
  11.    {
  12.       trace("lingo:" + str);
  13.    };
  14.    _global.statusBar = function(str)
  15.    {
  16.       getURL("javascript:void(window.status=\'" + str + "\')","");
  17.    };
  18. }
  19. _global.error = function(str)
  20. {
  21.    trace("error : " + str);
  22. };
  23. _global.Tardis = this;
  24. depth = 1;
  25. childlock = false;
  26. ChildLock = {};
  27. ChildLock.active = false;
  28. ChildLock.lockDialog = function()
  29. {
  30.    lingo("spriteDialog.show(\"child_lock\")");
  31. };
  32. ChildLock.unlockDialog = function()
  33. {
  34.    lingo("spriteDialog.show(\"child_unlock\")");
  35. };
  36. ChildLock.lock = function()
  37. {
  38.    this.active = true;
  39.    var node = sideMenu.mc_lock.node;
  40.    var str = node.attributes.lock;
  41.    node.attributes.lock = node.attributes.label;
  42.    node.attributes.label = str;
  43.    this.EB.broadcastMessage("childLockSet",true);
  44. };
  45. ChildLock.unlock = function()
  46. {
  47.    this.active = false;
  48.    var node = sideMenu.mc_lock.node;
  49.    var str = node.attributes.lock;
  50.    node.attributes.lock = node.attributes.label;
  51.    node.attributes.label = str;
  52.    this.EB.broadcastMessage("childLockSet",false);
  53. };
  54. ChildLock.EB = {};
  55. ASBroadcaster.initialize(ChildLock.EB);
  56. ConnCheck = {dbg:function(str)
  57. {
  58.    trace("ConnCheck." + str);
  59. },test:function()
  60. {
  61.    lingo("Flsh_connection_startCheck");
  62.    if(this.FAKE_CONNECTION != undefined)
  63.    {
  64.       this.onTestComplete(this.FAKE_CONNECTION);
  65.    }
  66. },onTimerComplete:function()
  67. {
  68.    this.test();
  69. },startTimer:function()
  70. {
  71.    this.test();
  72.    this.stopTimer();
  73.    this.nmTimerID = setInterval(this,"onTimerComplete",this.TIMER_INTERVAL * 1000);
  74. },stopTimer:function()
  75. {
  76.    this.dbg("stopTimer()");
  77.    clearInterval(this.nmTimerID);
  78. },TIMER_INTERVAL:null,DEBUG:"verbose"};
  79. UsageData = {dbg:function(str)
  80. {
  81.    trace("UsageData." + str);
  82. },init:function()
  83. {
  84.    var trySOprop = function(objSo, name, ┬ºset┬º)
  85.    {
  86.       var val = objSo.data[name];
  87.       if(val == null)
  88.       {
  89.          objSo.data[name] = eval("set");
  90.          return eval("set");
  91.       }
  92.       return val;
  93.    };
  94.    var makeUID = function()
  95.    {
  96.       return Math.random().toString().substr(2,7) + "" + Math.random().toString().substr(2,7);
  97.    };
  98.    var parent = this;
  99.    this.soIssue = SharedObject.getLocal("TardisV" + Tardis.Settings.version);
  100.    this.soGlobal = SharedObject.getLocal("TardisGlobal");
  101.    if(this.soIssue.getSize() > this.KB_LIMIT)
  102.    {
  103.       this.dbg("size has exceeded " + this.KB_LIMIT / 1024 + "Kb\nClearing log and ping data...");
  104.       this.soIssue.data.logData = [];
  105.       this.soIssue.data.pingData = [];
  106.       this.dbg("cleared. size is now  " + this.soIssue.getSize() / 1024 + "Kb");
  107.    }
  108.    var strUID = this.soGlobal.data.UID;
  109.    if(strUID == null || strUID == "")
  110.    {
  111.       this.FirstTime = true;
  112.       strUID = makeUID();
  113.    }
  114.    else
  115.    {
  116.       this.FirstTime = false;
  117.    }
  118.    this.soGlobal.data.UID = this.UID = strUID;
  119.    this.dbg("UID : " + this.UID);
  120.    this.logData = trySOprop(this.soGlobal,"logData",[]);
  121.    this.pingData = trySOprop(this.soIssue,"pingData",[]);
  122.    this.optin = trySOprop(this.soGlobal,"optin",true);
  123.    this.skipprizedraw = trySOprop(this.soIssue,"skipprizedraw",false);
  124.    this.times_intro_skip = trySOprop(this.soIssue,"times_intro_skip",false);
  125.    this.sponsor_intro_skip = trySOprop(this.soIssue,"sponsor_intro_skip",false);
  126.    this.soIssue.flush();
  127.    this.soGlobal.flush();
  128.    this.lastTime = null;
  129.    this.lastPage = null;
  130. },addPageEntry:function(pageValue)
  131. {
  132.    trace("UsageData : addPageEntry : pageValue : " + pageValue);
  133.    var now = getTimer();
  134.    var sessionGroup = this.logData[this.logData.length - 1];
  135.    if(this.lastTime != null)
  136.    {
  137.       var timeValue = Math.round((now - this.lastTime) / 1000);
  138.       var currEntries = sessionGroup.entries;
  139.       currEntries.push(timeValue + "." + this.lastPage);
  140.       this.dbg("addPageEntry : " + timeValue + "." + pageValue);
  141.    }
  142.    else
  143.    {
  144.       sessionGroup.startTime = this.getTimeStamp();
  145.    }
  146.    this.lastTime = now;
  147.    this.lastPage = pageValue;
  148. },addAdvertEntry:function(val)
  149. {
  150.    trace("UsageData : addAdvertEntry : value : " + val);
  151.    this.penultimateEntry = this.lastPage;
  152.    var strLog = Tardis.Sections.length + 1 + "." + val;
  153.    this.addPageEntry(strLog);
  154. },addAdvertEndEntry:function()
  155. {
  156.    this.addPageEntry(this.penultimateEntry);
  157. },addSessionGroup:function()
  158. {
  159.    var objG = {time:this.getTimeStamp(),entries:new Array(),startTime:null,version:Tardis.Settings.version};
  160.    this.logData.push(objG);
  161. },addPingEntry:function()
  162. {
  163.    var obj = {firsttime:this.FirstTime,time:this.getTimeStamp()};
  164.    this.pingData.push(obj);
  165. },findAndReplace:function(strStr, strSearch, strReplace)
  166. {
  167.    var i = 0;
  168.    var l = strStr.length;
  169.    var strTemp;
  170.    while(i < l)
  171.    {
  172.       if(strStr.charAt(i) == strSearch)
  173.       {
  174.          strTemp += strReplace;
  175.       }
  176.       else
  177.       {
  178.          strTemp += strStr.charAt(i);
  179.       }
  180.       i++;
  181.    }
  182.    return strTemp;
  183. },sendToServer:function()
  184. {
  185.    var strURL = "";
  186.    trace("UsageDate : sendToServer");
  187.    if(this.pingData.length > 0)
  188.    {
  189.       var objP = this.pingData[0];
  190.       var strBaseURL = this.PING_URL + "?";
  191.       var strQuery = "cd=" + Tardis.Settings.version + "&u=" + this.UID + "&t=" + objP.time;
  192.       if(objP.firsttime == true)
  193.       {
  194.          strQuery += "&first=1";
  195.       }
  196.    }
  197.    else
  198.    {
  199.       var objGroup = this.logData[0];
  200.       var arrEntries = objGroup.entries;
  201.       var len = arrEntries.length;
  202.       if(len == 0)
  203.       {
  204.          if(this.logData.length > 1)
  205.          {
  206.             this.dbg("empty cached group - deleting");
  207.             this.logData.shift();
  208.          }
  209.          else
  210.          {
  211.             this.dbg("no cached data - no new data");
  212.          }
  213.          if(this.logData.length > 1 && delete_counter < 100)
  214.          {
  215.             this.checkSend();
  216.          }
  217.          else
  218.          {
  219.             delete_counter = 0;
  220.          }
  221.          delete_counter++;
  222.          return undefined;
  223.       }
  224.       delete_counter = 0;
  225.       var len = Math.min(arrEntries.length,10);
  226.       var strBaseURL = this.LOG_URL + "?";
  227.       var strQuery = "";
  228.       strQuery += "cd=" + objGroup.version;
  229.       strQuery += "&u=" + this.UID;
  230.       strQuery += "&t=" + objGroup.time;
  231.       strQuery += "&s=" + objGroup.startTime;
  232.       strQuery += "&d=" + arrEntries.slice(0,len).join(":");
  233.       this.num_logs_sent = len;
  234.    }
  235.    strMacOsxSafeQuery = this.findAndReplace(strQuery,":","_");
  236.    strURL = strBaseURL + strMacOsxSafeQuery;
  237.    trace("-*- UsageData : sendToServer : strURL : " + strURL);
  238.    lingo("Flsh_usage_sendData(\"" + strURL + "\")");
  239.    this.active = true;
  240. },checkSend:function()
  241. {
  242.    if(this.active == false && (this.pingData.length > 0 || this.optin == true))
  243.    {
  244.       this.sendToServer();
  245.    }
  246.    else
  247.    {
  248.       this.dbg("no data to send");
  249.    }
  250. },onSent:function(success)
  251. {
  252.    with(this)
  253.    {
  254.       active = false;
  255.       dbg("data sent (" + success + ")");
  256.       if(success)
  257.       {
  258.          if(pingData.length > 0)
  259.          {
  260.             pingData.shift();
  261.          }
  262.          else
  263.          {
  264.             var entries = logData[0].entries;
  265.             entries.splice(0,num_logs_sent);
  266.             if(logData.length > 1 && entries.length == 0)
  267.             {
  268.                dbg("last group now empty - deleting");
  269.                logData.shift();
  270.             }
  271.          }
  272.          checkSend();
  273.       }
  274.       else
  275.       {
  276.          dbg("send failed");
  277.       }
  278.    }
  279. },setOptIn:function(val)
  280. {
  281.    trace("UsageData.setOptIn(" + val + ")");
  282.    this.optin = this.soGlobal.data.optin = val;
  283.    this.soGlobal.flush();
  284. },setSkipPrizeDraw:function(val)
  285. {
  286.    trace("UsageData.setSkipPrizeDraw(" + val + ")");
  287.    this.skipprizedraw = this.soIssue.data.skipprizedraw = val;
  288.    this.soIssue.flush();
  289. },deleteSoProp:function(SO, prop)
  290. {
  291.    delete this[SO].data[prop];
  292. },setSoProp:function(SO, prop, val)
  293. {
  294.    this[SO].data[prop] = val;
  295.    trace("val: " + val);
  296.    trace("setSoProp : prop : " + prop + " : " + " val : " + val);
  297.    this[SO].flush();
  298.    return val;
  299. },getSoProp:function(SO, prop)
  300. {
  301.    return this[SO].data[prop];
  302. },getTimeStamp:function()
  303. {
  304.    var pf = function(nm)
  305.    {
  306.       nm = nm.toString();
  307.       return nm.length != 1 ? nm : "0" + nm;
  308.    };
  309.    var d = new Date();
  310.    var s = "" + pf(d.getUTCDate()) + "." + pf(d.getUTCMonth() + 1) + "." + d.getUTCFullYear() + ":" + pf(d.getUTCHours()) + "." + pf(d.getUTCMinutes()) + "." + pf(d.getUTCSeconds());
  311.    return s;
  312. },LOG_URL:null,PING_URL:null,KB_LIMIT:10240,DEBUG:"none",delete_counter:0,active:false};
  313. SFX = {};
  314. SFX.volume_setting = 4;
  315. SFX.play = function(str)
  316. {
  317.    lingo("Flsh_soundPlay \"" + str + "\"");
  318. };
  319. SFX.setVolume = function(inc)
  320. {
  321.    lingo("Flsh_volume_set(" + inc + ")");
  322.    this.volume_setting = inc;
  323. };
  324. SFX.onVolumeGet = function(val)
  325. {
  326.    this.volume_setting = val;
  327. };
  328. SFX.init = function()
  329. {
  330.    lingo("Flsh_volume_get");
  331. };
  332. SFX.init();
  333. delete SFX.init;
  334.